home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 24 / CU Amiga Magazine's Super CD-ROM 24 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-07].iso / CUCD / Programming / SWI / source / lib / bim.pl < prev    next >
Encoding:
Text File  |  1994-01-31  |  4.2 KB  |  194 lines

  1. % $Id: bim.pl,v 1.1 1994/01/31 09:54:35 jan Exp $
  2. %
  3. % This file contains some predicates that are defined in BIM-prolog and
  4. % not in SWI-prolog (or at least not with the same meaning).
  5. % In case a predicate has a different meaning in SWI-prolog 
  6. % and in proLog by BIM renaming is done.
  7. % Remark that some predicates are only partially covered, feel free to add.
  8. %
  9. % author: Henk Vandecasteele
  10. %         Departement Computerwetenschappen
  11. %         Katholiek Universiteit Leuven
  12. %         Celestijnenlaan 200A
  13. %         3001 Heverlee
  14. %         BELGIUM
  15. %         henk.vandecasteele@cs.kuleuven.ac.be
  16. %
  17. % modified by Jan Wielemaker:
  18. %
  19. %      - Added module-declaration
  20. %      - Mapped writeClause/2 onto portray_clause/1
  21. %      - deleted the my... (SWI-Prolog can redefine predicates)
  22. %   
  23. % modified by Henk Vandecasteel:
  24. %
  25. %         - Added some missing predicates in the module-declaration.
  26. %         - Index/2 of proLog by BIM is transformed to index/1.
  27. %         - Fixed some bugs in the record-database-predicates.
  28.  
  29. module(bim,
  30.        [ please/2,
  31.      cputime/1,
  32.      include/1,
  33.      setdebug/0,
  34.      reconsult/1,
  35.      erase/1,            % BIM-compatible erase/1
  36.      rerecord/2,
  37.      erase_all/1,
  38.      record/3,
  39.      recorded/3,            % BIM-compatible recorded/3
  40.      inttoatom/2,
  41.      atomconcat/3,
  42.      update/1,
  43.      printf/2,
  44.      random/1,
  45.      index/2,
  46.      predicate_type/2,
  47.      vread/2,
  48.      bindVariables/1,
  49.      writeClause/2
  50.        ]).
  51.  
  52. :- op(700, xfx, <>).
  53.  
  54. % please/2 has no meaning in SWI-prolog (can't we map most actions to
  55. % other things (JW?). (Maybe, but it would not be very useful as please/2 
  56. % is usually called on-line. (HV) )
  57.  
  58. please(_, _).
  59.  
  60. cputime(Time):- 
  61.     statistics(cputime, Time).
  62.  
  63. % include/1 does not exist in SWI-prolog.
  64.  
  65. include(_).
  66.  
  67. % setdebug/0 has no meaning in SWI-prolog.
  68.  
  69. setdebug.
  70.  
  71. :- module_transparent reconsult/1.
  72.  
  73. reconsult(X):-
  74.     consult(X).
  75.  
  76. % erase/1 both exist in SWI-prolog and proLog by BIM.
  77.  
  78. erase(Key):- 
  79.     system:recorded(Key, _, Reference),
  80.     system:erase(Reference).
  81. erase(_).
  82.  
  83.  
  84. rerecord(Key, Value):-
  85.     system:recorded(Key, _,Reference),!,
  86.     system:erase(Reference),
  87.     recorda(Key, Value).
  88. rerecord(Key, Value):-    
  89.     recorda(Key, Value).
  90.  
  91.  
  92.  
  93. % the record-database with two keys of proLog by BIM is implemented with 
  94. % assert and retract.
  95.  
  96. erase_all(Key):- !,
  97.     retractall(data__(_, Key, _)).
  98.  
  99. erase_all(_).
  100.  
  101. record(Key1, Key2, Value):-
  102.         assert(data__(Key1, Key2, Value)).
  103.  
  104.  
  105. % recorded/3 has a different meaning in SWI-prolog. 
  106.  
  107. :- dynamic data__/3.
  108.  
  109. recorded(Key1, Key2, Value):-
  110.     data__(Key1, Key2, Value).
  111.  
  112. erase(Key1, Key2):-
  113.     retract(data__(Key1, Key2, _)).
  114.  
  115.  
  116. inttoatom(Int, Atom):-
  117.     int_to_atom(Int, Atom).
  118.  
  119. atomconcat(Atom1, Atom2, Atom3):-
  120.     concat(Atom1, Atom2, Atom3).
  121.  
  122. :- module_transparent update/1.
  123.  
  124. update(Clause):-
  125.     functor(Clause, Name, Arity),
  126.     functor(NewClause, Name, Arity),
  127.     retract(NewClause),!,
  128.     asserta(Clause).
  129. update(Clause):-
  130.     asserta(Clause).
  131.  
  132. printf(String, Param):-
  133.     writef(String, Param).
  134.  
  135. random(X):- X is random(1000000).
  136.  
  137.  
  138. % Mapping the BIM index/2 to the SWI index/1 directive.
  139.  
  140. instantiateOther(Index, Nr, Nr):- index(Index).
  141. instantiateOther(Index, ONr, Nr):-
  142.      NNr is ONr +1,
  143.     arg(NNr, Index, 0),
  144.     instantiateOther(Index, NNr, Nr).
  145. instantiateOther(Index, ONr, Nr):-
  146.     NNr is ONr + 1,
  147.     instantiateOther(Index, NNr, Nr).
  148.  
  149.  
  150. index(Pred/Nr, (Index1, Index2, Index3)):- 
  151.     functor(Term, Pred, Nr), 
  152.     arg(Index1, Term, 1),
  153.     arg(Index2, Term, 1),
  154.     arg(Index3, Term, 1),
  155.     instantiateOther(Term, 0, Nr).
  156. index(Pred/Nr, (Index1, Index2)):-
  157.     functor(Term, Pred, Nr), 
  158.     arg(Index1, Term, 1),
  159.     arg(Index2, Term, 1),
  160.     instantiateOther(Term, 0, Nr).
  161. index(Pred/Nr, Index):-
  162.     functor(Term, Pred, Nr), 
  163.     arg(Index, Term, 1),
  164.     instantiateOther(Term, 0, Nr).
  165.     
  166.  
  167.  
  168. predicate_type(reconsult(_), builtin). 
  169. predicate_type(Head, builtin):-
  170.     predicate_property(Head, built_in).
  171.  
  172. predicate_type(_, user). 
  173.  
  174. vread(Term, Variables):-
  175.     read_variables(Term, Variables).
  176.  
  177.  
  178. bindVariables([X = X | Bindings]):-
  179.     bindVariables(Bindings).
  180. bindVariables([]).
  181.  
  182. % writeClause/2 does the reverse of read_variables/2.  Hm? It used too.
  183.  
  184.  
  185. writeClause(Clause, Bindings) :-
  186.     bindVariablesForPortray(Bindings),
  187.     portray_clause(Clause),
  188.     fail.
  189. writeClause(_, _).
  190.  
  191. bindVariablesForPortray([X = '$$VAR'(X) | Bindings]) :-
  192.     bindVariablesForPortray(Bindings).
  193. bindVariablesForPortray([]).
  194.